﻿using Aker.DevTeam;
using Aker.Uretim;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;
using Extensions;
using System;
using System.Data;

namespace Aker.Product
{
    public partial class YeniImalatKarti2 : XForm
    {
        public delegate void ProductInsertedEventHandler(int ProductId, string Artikel, int StokKartiTipi);
        public event ProductInsertedEventHandler ProductInserted;

        DataTable dtHammadde = null;
        //DataTable dtRecete = null;
        DataTable dtMaliyet = null;

        DataTable dtProductGLE = null;
        int GelenProductId = -1;
        bool siparisten = false;

        bool loading = false;

        private void InitLocal()
        {
            if (Data.DB.Currency.Rows.Count == 0)
                Data.TAM.CurrencyTableAdapter.Fill(Data.DB.Currency);

            if (Data.DB.OrmeMakinesi.Rows.Count == 0)
                Data.TAM.OrmeMakinesiTableAdapter.Fill(Data.DB.OrmeMakinesi);

            if (Data.DB.Currency.Rows.Count == 0)
                Data.TAM.CurrencyTableAdapter.Fill(Data.DB.Currency);


            dtHammadde = Data.DM.ExecuteDataSet("GetHammaddeStok", 3, DBNull.Value).Tables[0];
            DataTable dtIp = dtHammadde.Select("GrupKodu like 'İ%'").CopyToDataTable();

            gleIp1.Properties.Assign(Utility.GetAutoCompGLE(dtIp, "Grup", "GrupKodu"));
            gleIp2.Properties.Assign(Utility.GetAutoCompGLE(dtIp, "Grup", "GrupKodu"));
            gleIp3.Properties.Assign(Utility.GetAutoCompGLE(dtIp, "Grup", "GrupKodu"));
            gleIp4.Properties.Assign(Utility.GetAutoCompGLE(dtIp, "Grup", "GrupKodu"));

            dtProductGLE = Data.DM.ExecuteDataTable("GetProductGLE", 2);
            gleBazArtikel.Properties.Assign(Utility.GetAutoCompGLE(dtProductGLE, "Article", "Article"));
            gleBazArtikel.EditValueChanged += gleBazArtikel_EditValueChanged;


            gvMaliyet11.OptionsView.NewItemRowPosition = NewItemRowPosition.Bottom;

            gleMakineCinsi.Properties.Assign(Utility.GetAutoCompGLE(Data.DB.OrmeMakinesi, "OrguCinsi", "OrmeMakinesiId"));

            cmbUretimTipi.SelectedIndex = 1;
            cmbUretimTipi.SelectedIndexChanged += cmbUretimTipi_SelectedIndexChanged;

            cmbGrup.SelectedIndex = 0;
            cmbKompozisyon11.SelectedIndex = 0;
        }

        public YeniImalatKarti2() //Ribbon'dan
        {
            InitializeComponent();
            InitLocal();
            InitMaliyetGv(dtMaliyet);

            GetNewCode();
        }

        public YeniImalatKarti2(int ProductId) //İmalat Kartından
        {
            InitializeComponent();
            InitLocal();

            GelenProductId = ProductId;
            LoadProductDetail(GelenProductId);
        }

        public YeniImalatKarti2(int ProductId, bool oldProduct) //Artikel listesinden
        {
            InitializeComponent();

            InitLocal();

            GelenProductId = ProductId;
            LoadProductDetail(GelenProductId);
        }

        public YeniImalatKarti2(string bazArtikel, int uretimTipi, decimal qty, bool isKG) //Sipariş sayfasından
        {
            siparisten = true;
            InitializeComponent();
            InitLocal();

            teQty.EditValue = qty;

            if (bazArtikel != "")
            {
                //if (gleBazArtikel.GetSelectedDataRow() != null)
                {
                    gleBazArtikel.EditValue = bazArtikel;
                    int productId = (gleBazArtikel.GetSelectedDataRow() as DataRowView).Row["ProductId"].ToIntNN();
                    LoadProductDetail(productId);
                }
            }

            cmbMtKg.SelectedIndex = isKG ? 1 : 0;
            cmbUretimTipi.SelectedIndex = uretimTipi;

            GetNewCode();
        }

        private void InitMaliyetGv(DataTable dtMaliyet)
        {
            //if (dtMaliyet == null)
            //{
            //    dtMaliyet = new DataTable();
            //    dtMaliyet.Columns.Add("MaliyetAciklama", typeof(string));
            //}

            //gvMaliyet11.Init(dtMaliyet);
            ////gvMaliyet11.Columns["CurrencyId"].ColumnEdit = Utility.GetAutoCompGLE(Data.DB.Currency, "Name", "CurrencyId");
        }

        public void HarmanHesapla()
        {
            //    double girisGramaj = Convert.ToDouble(seGirisGramaj20.EditValue);
            //    if (girisGramaj < 1)
            //        return;

            //    int qty = teQty.EditValue.ToIntNN();
            //    if (qty < 1)
            //        return;

            //    int ipAdedi = cmbZeminIpiTipi.SelectedIndex + 1;
            //    string zeminIpi = gleZeminIpi.Text.Trim();

            //    int zeminIpiGramaji = zeminIpi.Split('/')[0].ToIntNN() / 3;

            //    double fire = 1 + seFire.EditValue.ToIntNN() / 100.0;

            //    double zeminIpiOrani = (zeminIpiGramaji / girisGramaj) * ipAdedi;
            //    double carpan = (teQty.EditValue.ToIntNN() * girisGramaj / 1000.0) * 1.5;

            //    double zeminIpiQty = carpan * zeminIpiOrani;
            //    double hammaddeQty = carpan * (1 - zeminIpiOrani) * fire;


        }

        private void HarmanHesapla(SpinEdit seKafa, GridView gvKafa, double hammaddeQty)
        {
            //if (gvKafa.DataSource == null)
            //    return;

            //gvKafa.EndEditing();
            //double kafaOran = seKafa.EditValue.ToIntNN() / 100.0;
            //DataTable dtKafa = (gvKafa.DataSource as DataView).Table;
            //foreach (DataRow dr in dtKafa.Rows)
            //{
            //    double satirOran = dr["Oran"].ToIntNN() / 100.0;
            //    double qty = hammaddeQty * kafaOran * satirOran;

            //    dr["HarmanKg"] = qty;
            //}
        }

        private void seHarman_EditValueChanged(object sender, EventArgs e)
        {
            //HarmanHesapla();
        }

        private void gleBazArtikel_EditValueChanged(object sender, EventArgs e)
        {
            cmbGrup.SelectedIndexChanged -= cmbGrup_SelectedIndexChanged;
            cmbUretimTipi.SelectedIndexChanged -= cmbUretimTipi_SelectedIndexChanged;

            if (gleBazArtikel.Text.StartsWith("11."))
                cmbGrup.SelectedIndex = 0;
            if (gleBazArtikel.Text.StartsWith("12."))
                cmbGrup.SelectedIndex = 1;
            if (gleBazArtikel.Text.StartsWith("30"))
                cmbGrup.SelectedIndex = 2;

            int bazProductId = (gleBazArtikel.GetSelectedDataRow() as DataRowView).Row["ProductId"].ToIntNN();
            LoadProductDetail(bazProductId, true);

            GetNewCode();

            cmbUretimTipi.SelectedIndexChanged += cmbUretimTipi_SelectedIndexChanged;
            cmbGrup.SelectedIndexChanged += cmbGrup_SelectedIndexChanged;

            //TODO:KG BazProductId = gleBazArtikel.EditValue.ToIntNN();
        }

        private void cmbGrup_SelectedIndexChanged(object sender, EventArgs e)
        {
            gleBazArtikel.EditValue = null;
            if (!loading)
                GetNewCode();
        }

        private void cmbMtKg_SelectedIndexChanged(object sender, EventArgs e)
        {
            // HarmanHesapla();
        }

        private void LoadSentezDetail()
        {
            DataSet ds = null;
            string bazArtikel = gleBazArtikel.EditValue.ToStringNN();
            try
            {
                ds = Data.DMServer.ExecuteDataSet("GetSentezArtikel", bazArtikel);
            }
            catch (Exception ex) //bağlantı yoksa!
            {
                //XtraMessageBox.Show(ex.ToString());
                ds = Data.DMLocal.ExecuteDataSet("GetSentezArtikelLocal", bazArtikel);
            }

            bool found = ds.Tables[0].Rows.Count > 0;
            gcSentez.Visible = found;

            if (!found)
                return;

            gcSentez.Text = bazArtikel + " Sentez Detayı";

            DataRow drSK = ds.Tables[0].Rows[0];
            DataTable dt = new DataTable();
            dt.Columns.Add(Language.Sentez.Attribute, typeof(string));
            dt.Columns.Add(Language.Sentez.Value, typeof(string));

            foreach (DataColumn dc in ds.Tables[0].Columns)
                dt.Rows.Add(dc.ColumnName, drSK[dc].ToStringNN());

            gvSK.Init(dt);
            gvSK.ViewCaption = Language.Sentez.StokKarti;
            gvSK.BestFitColumns();

            gvHammadde.Init(ds.Tables[1]);
            gvHammadde.ViewCaption = Language.Sentez.Hammadde;
            gvHammadde.MakeColumnInvisible("Article");
            gvHammadde.SetCaptions("HammaddeSira:#", "Iplik:" + Language.Sentez.Hammadde, "IplikAciklama:" + Language.Sentez.Aciklama, "IplikMiktar:" + Language.Sentez.Kullanim, "Detay:" + Language.Sentez.Detail);
            gvHammadde.BestFitColumns();

            gvAciklama.Init(ds.Tables[2]);
            gvAciklama.ViewCaption = Language.Sentez.StokKartiDetayi;
            gvAciklama.MakeColumnInvisible("Article");
            gvAciklama.SetCaptions("AciklamaSira:#", "Aciklama:" + Language.Sentez.Aciklama);
            gvAciklama.BestFitColumns();
        }

        private void cmbUretimTipi_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!loading)
                GetNewCode();

            //if (cmbUretimTipi.SelectedIndex < 2)
            //{
            //    cmbGrup.ReadOnly = false;
            //    cmbKompozisyon11.ReadOnly = false;
            //    seGirisGramaj.ReadOnly = false;
            //    seFinalGramaj11.ReadOnly = false;
            //}
            //else
            //{
            //    LoadProductDetail();
            //    cmbGrup.ReadOnly = true;
            //    cmbKompozisyon11.ReadOnly = true;
            //    seGirisGramaj.ReadOnly = true;
            //    seFinalGramaj11.ReadOnly = true;
            //}

            //GetNewCode();
        }

        private void Save11(AkerDB.ProductDetayRow drDetay)
        {
            drDetay.ReferansArtikel = gleBazArtikel.EditValue.ToStringNN();
            drDetay.ProductGrupId = cmbGrup.SelectedIndex + 1;

            drDetay.DesenNo = txtDesenNo.Text;
            if (drDetay.DesenNo == "")
                drDetay.SetDesenNoNull();

            drDetay.Aciklama = txtAciklama.Text;
            if (drDetay.Aciklama == "")
                drDetay.SetAciklamaNull();

            drDetay.KompozisyonId = cmbKompozisyon11.SelectedIndex + 1;

            drDetay.Fire = seFire11.EditValue.ToIntNN();
            if (drDetay.Fire == 0)
                drDetay.SetFireNull();

            drDetay.GirisGr = seGirisGramaj.EditValue.ToIntNN(); ;
            if (drDetay.GirisGr < 1)
                drDetay.SetGirisGrNull();

            drDetay.FinishGr = seFinalGramaj11.EditValue.ToIntNN();
            if (drDetay.FinishGr < 1)
                drDetay.SetFinishGrNull();

            drDetay.IpGrupKodu1 = gleIp1.EditValue.ToStringNN();
            if (drDetay.IpGrupKodu1 == "")
                drDetay.SetIpGrupKodu1Null();

            drDetay.IpGrupKodu2 = gleIp2.EditValue.ToStringNN();
            if (drDetay.IpGrupKodu2 == "")
                drDetay.SetIpGrupKodu2Null();

            drDetay.IpGrupKodu3 = gleIp3.EditValue.ToStringNN();
            if (drDetay.IpGrupKodu3 == "")
                drDetay.SetIpGrupKodu3Null();

            drDetay.IpGrupKodu4 = gleIp4.EditValue.ToStringNN();
            if (drDetay.IpGrupKodu4 == "")
                drDetay.SetIpGrupKodu4Null();


            drDetay.Ormeci = txtOrmeci.Text;
            if (drDetay.Ormeci == "")
                drDetay.SetOrmeciNull();


            drDetay.SIKLIK = txtSıklık.Text;
            if (drDetay.SIKLIK == "")
                drDetay.SetSIKLIKNull();

            drDetay.OrguSekliId = cmbOrguSekli.SelectedIndex + 1;

            drDetay.LycraId = cmbLycra.SelectedIndex + 1;

            drDetay.OrmeMakinesiId = gleMakineCinsi.EditValue.ToIntNN();

            if (teQty.Visible == true)
                drDetay.QtyManuel = teQty.EditValue.ToDecimalNN();


            //drDetay.Dink = chkDink11.Checked;
            //drDetay.Sardon = cmbSardon11.SelectedIndex + 1;
            //drDetay.RamId = cmbRamId11.SelectedIndex + 1;

            //drDetay.RamIsi = seRamIsi11.EditValue.ToIntNN();
            //if (drDetay.RamIsi < 0)
            //    drDetay.SetRamIsiNull();

            //drDetay.FinalEn = seFinalEn11.EditValue.ToIntNN();
            //if (drDetay.FinalEn < 0)
            //    drDetay.SetFinalEnNull();

            //drDetay.Boyahane = txtBoyahane.Text;
            //if (drDetay.Boyahane == "")
            //    drDetay.SetBoyahaneNull();

            //drDetay.OnFikse = chkOnFikse.Checked;
            //drDetay.Yikama = chkYikama.Checked;
            //drDetay.Boya = chkBoya.Checked;
            //drDetay.KenarKesim = chkKenarKesim.Checked;

            //drDetay.Baski = txtBaski.Text;
            //if (drDetay.Baski == "")
            //    drDetay.SetBaskiNull();

            //drDetay.Baskici = txtBaskici.Text;
            //if (drDetay.Baskici == "")
            //    drDetay.SetBaskiciNull();

            //drDetay.Sanfor = chkSanfor.Checked;

            //drDetay.Firca = txtFirca.Text;
            //if (drDetay.Firca == "")
            //    drDetay.SetFircaNull();

            //drDetay.Hiz = txtHiz.Text;
            //if (drDetay.Hiz == "")
            //    drDetay.SetHizNull();

            //drDetay.KenarKola = txtKenarKola.Text;
            //if (drDetay.KenarKola == "")
            //    drDetay.SetKenarKolaNull();

            //drDetay.Parlatma = txtParlatma.Text;
            //if (drDetay.Parlatma == "")
            //    drDetay.SetParlatmaNull();

            //drDetay.BaskiTipi = txtTipi.Text;
            //if (drDetay.BaskiTipi == "")
            //    drDetay.SetBaskiTipiNull();

            //drDetay.DesenNo = txtDeseni.Text;
            //if (drDetay.DesenNo == "")
            //    drDetay.SetDesenNoNull();

            //drDetay.Cekmezlik = txtCekmezlik.Text;
            //if (drDetay.Cekmezlik == "")
            //    drDetay.SetCekmezlikNull();

            //drDetay.YikamaHasligi = txtYikamaHasligi.Text;
            //if (drDetay.YikamaHasligi == "")
            //    drDetay.SetYikamaHasligiNull();

            //drDetay.SurtunmeHasligi = txtSurtHasligi.Text;
            //if (drDetay.SurtunmeHasligi == "")
            //    drDetay.SetSurtunmeHasligiNull();

            //drDetay.YikamaTalimati = txtYikamaTalimati.Text;
            //if (drDetay.YikamaTalimati == "")
            //    drDetay.SetYikamaTalimatiNull();

        }

        private void btnKaydet_Click(object sender, EventArgs e)
        {
            AkerDB.ProductRow drProduct = null;
            AkerDB.ProductDetayRow drDetay = null;

            if (siparisten)
            {
                drProduct = Data.DB.Product.NewProductRow();
                Data.DB.Product.AddProductRow(drProduct);

                drDetay = Data.DB.ProductDetay.NewProductDetayRow();
                Data.DB.ProductDetay.Rows.Add(drDetay);
            }
            else
            {
                Data.TAM.ProductDetayTableAdapter.Fill(Data.DB.ProductDetay);
                drProduct = Data.DB.Product.FindByProductId(GelenProductId);
                drDetay = (AkerDB.ProductDetayRow)Data.DB.ProductDetay.Select("ProductId = " + drProduct.ProductId)[0];
            }



            drProduct.Article = txtYeniKod.Text;
            if (gleIp1.EditValue.ToStringNN() == "")
            {
                XtraMessageBox.Show("1.İp boş olamaz!");
                return;
            }

            drProduct.ModifiedBy = AppSession.UserInfo.UserId;
            drProduct.ModifiedOn = DateTime.Now;



            Data.SaveProduct(drProduct);


            drDetay.ProductId = drProduct.ProductId;

            Save11(drDetay);
            //foreach (DataRow dr in (gvMaliyet11.DataSource as DataView).Table.Rows)
            //{
            //    AkerDB.ProductMaliyetRow drMaliyet = Data.DB.ProductMaliyet.NewProductMaliyetRow();
            //    drMaliyet.ProductId = drProduct.ProductId;// BazProductId;
            //    drMaliyet.Aciklama = dr["MaliyetAciklama"].ToStringNN();
            //    drMaliyet.CurrencyId = dr["CurrencyId"].ToIntNN();
            //    drMaliyet.Fiyat = dr["Fiyat"].ToDecimalNN();
            //    Data.DB.ProductMaliyet.Rows.Add(drMaliyet);
            //    Data.TAM.ProductMaliyetTableAdapter.Update(drMaliyet);
            //}

            Data.TAM.ProductDetayTableAdapter.Update(drDetay);


            if (Environment.MachineName != "KGULCAN")
                btnKaydet.Enabled = false;

            GelenProductId = drProduct.ProductId;

            if (!siparisten) //siparişten geliyorsa, zaten productId sipariş formunda güncelleniyor ve rapor sonra gösteriliyor...
                AppSession.MainForm.ShowMdiChildForm(typeof(ImalatKartlari), GelenProductId);

            if (ProductInserted != null)
                ProductInserted(GelenProductId, drProduct.Article, 2);
        }

        private void LoadProductDetail(int id, bool onlyBazArtikelChanged = false)
        {
            LoadSentezDetail();

            DataSet dsProductDetail = Data.DM.ExecuteDataSet("GetProductDetail", id);

            if (dsProductDetail.Tables[0].Rows.Count == 0)
                return;

            //InitMaliyetGv(dsProductDetail.Tables[1]);

            DataRow drDetail = dsProductDetail.Tables[0].Rows[0];

            cmbGrup.SelectedIndex = drDetail["ProductGrupId"].ToComboIndex();
            txtDesenNo.Text = drDetail["DesenNo"].ToStringNN();
            txtAciklama.Text = drDetail["Aciklama"].ToStringNN();
            cmbKompozisyon11.SelectedIndex = drDetail["KompozisyonId"].ToComboIndex();

            seFire11.EditValue = drDetail["Fire"].ToIntNN(0);
            seGirisGramaj.EditValue = drDetail["GirisGr"].ToIntNN(0);
            seFinalEn11.EditValue = drDetail["FinalEn"].ToIntNN(0);

            gleIp1.EditValue = drDetail["IpGrupKodu1"].ToStringNN();
            gleIp2.EditValue = drDetail["IpGrupKodu2"].ToStringNN();
            gleIp3.EditValue = drDetail["IpGrupKodu3"].ToStringNN();
            gleIp4.EditValue = drDetail["IpGrupKodu4"].ToStringNN();

            txtOrmeci.Text = drDetail["Ormeci"].ToStringNN();
            txtSıklık.Text = drDetail["SIKLIK"].ToStringNN();

            cmbOrguSekli.SelectedIndex = drDetail["OrguSekliId"].ToComboIndex();
            cmbLycra.SelectedIndex = drDetail["LycraId"].ToComboIndex();

            gleMakineCinsi.EditValue = drDetail["OrmemakinesiId"].ToIntNN();


            //cmbRamId11.SelectedIndex = drDetail["RamId"].ToComboIndex();
            //cmbSardon11.SelectedIndex = drDetail["Sardon"].ToComboIndex();

            //seFinalGramaj11.EditValue = drDetail["FinishGr"].ToIntNN(0);
            //seRamIsi11.EditValue = drDetail["RamIsi"].ToIntNN(0);

            //txtCekmezlik.Text = drDetail["Cekmezlik"].ToStringNN();
            //txtYikamaHasligi.Text = drDetail["YikamaHasligi"].ToStringNN();
            //txtSurtHasligi.Text = drDetail["SurtHasligi"].ToStringNN();
            //txtYikamaTalimati.Text = drDetail["YikamaTalimati"].ToStringNN();

            //txtBoyahane.Text = drDetail["Boyahane"].ToStringNN();
            //txtBaski.Text = drDetail["Baski"].ToStringNN();
            //txtBaskici.Text = drDetail["Baskici"].ToStringNN();
            //txtTipi.Text = drDetail["BaskiTipi"].ToStringNN();
            //txtFirca.Text = drDetail["Firca"].ToStringNN();
            //txtHiz.Text = drDetail["Hiz"].ToStringNN();
            //txtKenarKola.Text = drDetail["KenarKola"].ToStringNN();
            //txtParlatma.Text = drDetail["Parlatma"].ToStringNN();
            //txtAciklama11.Text = drDetail["Aciklama"].ToStringNN();

            //chkDink11.Checked = (bool)drDetail["Dink"];
            //chkSanfor.Checked = (bool)drDetail["Sanfor"];
            //chkBoya.Checked = (bool)drDetail["Boya"];
            //chkYikama.Checked = (bool)drDetail["Yikama"];
            //chkOnFikse.Checked = (bool)drDetail["OnFikse"];
            //chkKenarKesim.Checked = (bool)drDetail["KenarKesim"];

            if (teQty.Visible == true)
                teQty.Text = drDetail["QtyManuel"].ToStringNN();
        }

        private void gleMakineCinsi_EditValueChanged(object sender, EventArgs e)
        {
            if (gleMakineCinsi.EditValue.ToIntNN() != -1)
            {
                DataTable dt = Data.DB.OrmeMakinesi.Select("OrmeMakinesiId=" + gleMakineCinsi.EditValue).CopyToDataTable();
                txtPus.Text = dt.Rows[0]["PUS"].ToStringNN();
                txtFayn.Text = dt.Rows[0]["Fine"].ToStringNN();
                txtSistem.Text = dt.Rows[0]["Sistem"].ToStringNN();
            }
        }


        private void GetNewCode()
        {
            string sonArtikel = "";
            Kod sonKod = null;
            string filtre = "";
            Kod Yeni = null;
            DataRow[] drsFiltered;
            string bazArtikel = gleBazArtikel.EditValue.ToStringNN();

            string filtreOnEk = "";
            switch (cmbGrup.SelectedIndex)
            {

                case 0: //11                    
                    filtreOnEk = "11." + DateTime.Now.Year.ToString().Substring(2, 2);
                    break;
                case 1: //12                    
                    filtreOnEk = "12." + DateTime.Now.Year.ToString().Substring(2, 2);
                    break;
                case 2:  //30 
                    filtreOnEk = "30.";
                    break;
            }

            switch (cmbUretimTipi.SelectedIndex)
            {
                case 0: //aynı artikel
                    if (bazArtikel == "")
                    {
                        ShowError("Baz artikel seçmelisiniz!");
                        return;
                    }

                    sonKod = new Kod(bazArtikel);
                    filtre = "Article like '" + sonKod.KodPartisiz + "%'";
                    drsFiltered = dtProductGLE.Select(filtre);
                    for (int i = drsFiltered.Length - 1; i > -1; i--)
                    {
                        DataRow dr = drsFiltered[i];
                        Kod arananKod = new Kod(dr["Article"].ToStringNN());
                        if (sonKod.Renk == arananKod.Renk)
                        {
                            sonKod = arananKod.Copy();
                            break;
                        }
                    }

                    Yeni = sonKod.PartiNoArtir();
                    txtYeniKod.Text = Yeni.KodPartisiz;
                    txtPartiNo.Text = Yeni.PartiNo;
                    break;
                case 1:  //yeni artikel
                    filtre = "Article like '" + filtreOnEk + "%'";
                    drsFiltered = dtProductGLE.Select(filtre);
                    if (drsFiltered.Length > 0)
                        sonArtikel = drsFiltered[drsFiltered.Length - 1]["Article"].ToStringNN();
                    else
                        sonArtikel = filtreOnEk + "000";

                    sonKod = new Kod(sonArtikel);

                    if (drsFiltered.Length > 0)
                        Yeni = sonKod.SiraNoArtir();
                    else
                        Yeni = sonKod.Copy();

                    txtYeniKod.Text = Yeni.KodPartisiz;
                    txtPartiNo.Text = Yeni.PartiNo;
                    break;
                case 2: //renk
                    if (bazArtikel == "")
                    {
                        ShowError("Baz artikel seçmelisiniz!");
                        return;
                    }

                    sonKod = new Kod(bazArtikel);

                    filtre = "Article like '" + sonKod.KodRenksizPartisiz + "%'";
                    drsFiltered = dtProductGLE.Select(filtre);
                    sonArtikel = drsFiltered[drsFiltered.Length - 1]["Article"].ToStringNN();

                    sonKod = new Kod(sonArtikel);
                    Yeni = sonKod.RenkOlustur();
                    txtYeniKod.Text = Yeni.KodPartisiz;
                    txtPartiNo.Text = Yeni.PartiNo;
                    break;
            }

            AppSession.MainForm.Notify("Baz alınan kod:" + sonKod.KodPartili);
        }
    }
}